package codingStudy.netEase2018Spring;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

/**
 * @author dell
 * @category 奇怪表达式
 */
public class OddExpression {
	static int solve(String s) {
		char[] expresion = s.toCharArray();
		Deque<Integer> nums = new ArrayDeque<Integer>();
		Deque<String> symbols = new ArrayDeque<String>();
		// 1. 将输出的表达式处理，将运算符和数字分离。
		for (int i = 0; i < expresion.length; i++) {
			String a = String.valueOf(expresion[i]);
			if (expresion[i] == '+' || expresion[i] == '-'
					|| expresion[i] == '*') {
				symbols.offer(a);
			} else {
				nums.offer(Integer.valueOf(a));
			}
		}

		while (symbols.size() != 0) {
			String symbol = symbols.poll();
			if (symbol.equals("+")) {
				int a = nums.poll();
				int b = nums.poll();
				nums.offerFirst(a + b);
			} else if (symbol.equals("-")) {
				int a = nums.poll();
				int b = nums.poll();
				nums.offerFirst(a - b);

			} else if (symbol.equals("*")) {
				int a = nums.poll();
				int b = nums.poll();
				nums.offerFirst(a * b);
			}

		}

		// 2. 计算表达式

		return nums.getFirst();

	}

	public static void main(String[] args) {
		// Scanner sc = new Scanner(System.in);
		// String experssion = sc.next();
		// System.out.println(solve(experssion));
		// sc.close();
		System.out.println(solve("7*9-2*0+2"));
	}
}
